using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using System.Linq;

namespace MedicalManagementSystem.Helpers
{
    public static class CustomHtmlHelper
    {
        public static string ExportJS(this HtmlHelper html, string fileName)
        {
            var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
            var absolutePath = urlHelper.Content(String.Format("~/Scripts/{0}", fileName));
            return string.Format(String.Format("<script src=\"{0}\" type=\"text/javascript\"></script>", absolutePath));
        }

        public static string LinkStylesheet(this HtmlHelper html, string fileName)
        {
            var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
            var absolutePath = urlHelper.Content(String.Format("~/Content/{0}", fileName));
            return String.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", absolutePath);
        }


        public static string Image(this HtmlHelper helper,
                                    string url,
                                    string altText,
                                    object htmlAttributes)
        {
            TagBuilder builder = new TagBuilder("img");
            builder.Attributes.Add("src", url);
            builder.Attributes.Add("alt", altText);
            builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            return builder.ToString(TagRenderMode.SelfClosing);
        }

        public static string DropDownList(this HtmlHelper html, string name, IDictionary<int,string> dict, 
            int selectedItem, object htmlAttribytes = null)
        {
            var htmlItems = dict.Select(item => new SelectListItem
                                                    {
                                                        Selected = item.Key == selectedItem,
                                                        Text = item.Value,
                                                        Value = item.Key.ToString(),
                                                    });
            return  html.DropDownList(name, htmlItems, htmlAttribytes).ToHtmlString();
        }


    }
}